/**
 * 
 */
package Tests;

import static org.junit.Assert.*;

import java.lang.reflect.Field;
import java.math.BigDecimal;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import Chocolatier.ConditionneurChocolatier;
import Chocolatier.FabricantChocolatier;

/**
 * @author Vincent
 *
 */
public class ConditionneurChocolatierTest
{
	private FabricantChocolatier fc1;
	private FabricantChocolatier fc2;
	private ConditionneurChocolatier cc1;
	private ConditionneurChocolatier cc2;
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		fc1 = new FabricantChocolatier("noir", 1,new BigDecimal("5.00"));
		fc2 = new FabricantChocolatier("blanc", 2,new BigDecimal("6.00"));
		cc1 = ConditionneurChocolatier.getInstance();
		cc2 = ConditionneurChocolatier.getInstance();
	}

	/**
	 * @throws Exception
	 *             Allows to recreate an instance of the singleton class for each
	 *             tests
	 */
	@Before
	public void resetSingleton() throws Exception
	{
		Field instance = Chocolatier.ConditionneurChocolatier.class
				.getDeclaredField("instance");
		instance.setAccessible(true);
		instance.set(null, null);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception
	{
	}

	/**
	 * Checks the ConditionneurChocolatier unicity
	 */
	@Test
	public void testSingleInstance() throws Exception
	{
		assertEquals(fc1.equals(fc2), false);
		assertEquals(cc1.equals(cc2), true);
		assertEquals(cc1.getNumChocolatier(),cc2.getNumChocolatier());
	}
	
	/**
	 * Checks the ConditionneurChocolatier unicity
	 */
	@Test
	public void testListeMagasinsUnique() throws Exception
	{
		cc1.addMagasin("Magasin PARIS 75008");
		cc2.addMagasin("Magasin PARIS 75008");
		assertEquals(cc2.getListeMagasins().size(),1);
		
	}
	
	/**
	 * Checks the ConditionneurChocolatier special field is initialized with value false
	 */
	@Test
	public void testPasDePeriodeSpecial(){
		assertEquals(cc1.isSpecial(), false);
	}
	
	/**
	 * Checks the ConditionneurChocolatier  coeff is correctly initialized
	 */
	@Test
	public void testCoeff(){
		assertEquals(cc1.getCoeff(), new BigDecimal("1.00"));
		cc1.setCoeff(new BigDecimal("1.17"));
		assertEquals(cc1.getCoeff(), new BigDecimal("1.17"));
	}
	
	
	

}
